/**测试函数合集，用来检测游戏的性能，是否内存泄露等等 */
var GTest = {

    /**初始化测试数据 */
    init(){
        this.allChildrenCount = 0;
    },

    /**清除数据，重新计算所有子节点 */
    renewCountAllChildNum(parent){
        parent = parent || cc.director.getScene();
        //记录父节点名字
        this.parentName = parent.name;
        this.init();
        this.countAllChildNum(parent);
    },

    /**计算parent节点下的所有子节点个数，如果个数一直增加，说明有内存泄露   
     * parent 默认为当前场景
    */
    countAllChildNum(parent){
        parent = parent || cc.director.getScene();
        this[parent.name + "childrenCount"] = 0;
        this[parent.name + "childrenCount"] += parent.childrenCount;
        this.allChildrenCount += parent.childrenCount;
        for(var i = 0; i < parent.childrenCount; i++){
            if(parent.children[i].childrenCount > 0){
                this.countAllChildNum(parent.children[i]);
            }
        }
        console.warn(parent.name + "的直接子节点个数为", this[parent.name + "childrenCount"], "累计子节点个数为", this.allChildrenCount);
        if(parent.__proto__ instanceof cc.Node){//为场景
            console.error("当前场景的总子节点数为", this.allChildrenCount);
        }
        if(this.parentName === parent.name){
            console.error("当前节点的总子节点数为", this.allChildrenCount);
        }
    },
};

window.GTest = GTest;
GTest.init();